package com.quiz.bis.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.quiz.bis.domain.vo.BisKnowPointsVo;
import com.quiz.bis.domain.model.BisKnowPoints;
import com.quiz.common.core.domain.R;
import com.quiz.common.mybatis.core.page.PageQuery;
import com.quiz.common.mybatis.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quiz.common.annotation.Log;
import com.quiz.common.core.controller.BaseController;
import com.quiz.common.core.domain.AjaxResult;
import com.quiz.common.enums.BusinessType;
import com.quiz.bis.service.IBisKnowPointsService;
import com.quiz.common.utils.poi.ExcelUtil;

/**
 * 知识点Controller
 *
 * @author ahuan
 * @date 2025-03-09
 */
@RestController
@RequestMapping("/question/know")
@Tag(name = "知识点管理")
public class BisKnowPointsController extends BaseController {
    @Autowired
    private IBisKnowPointsService bisKnowPointsService;

    /**
     * 查询知识点列表
     */
    @PreAuthorize("@ss.hasPermi('know:points:list')")
    @GetMapping("/list")
    public TableDataInfo<BisKnowPointsVo> list(BisKnowPoints bisKnowPoints, PageQuery pageQuery) {
        return bisKnowPointsService.selectBisKnowPointsList(bisKnowPoints, pageQuery);
    }

    /**
     * 导出知识点列表
     */
    @PreAuthorize("@ss.hasPermi('know:points:export')")
    @Log(title = "知识点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisKnowPoints bisKnowPoints) {
        List<BisKnowPoints> list = bisKnowPointsService.selectBisKnowPointsList(bisKnowPoints);
        ExcelUtil<BisKnowPoints> util = new ExcelUtil<BisKnowPoints>(BisKnowPoints.class);
        util.exportExcel(response, list, "知识点数据");
    }

    /**
     * 获取知识点详细信息
     */
    @PreAuthorize("@ss.hasPermi('know:points:query')")
    @GetMapping(value = "/{id}")
    public R<BisKnowPointsVo> getInfo(@PathVariable("id") Long id) {
        return R.ok(bisKnowPointsService.selectBisKnowPointsById(id));
    }

    /**
     * 新增知识点
     */
    @PreAuthorize("@ss.hasPermi('know:points:add')")
    @Log(title = "知识点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BisKnowPoints bisKnowPoints) {
        return toAjax(bisKnowPointsService.insertBisKnowPoints(bisKnowPoints));
    }

    /**
     * 修改知识点
     */
    @PreAuthorize("@ss.hasPermi('know:points:edit')")
    @Log(title = "知识点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BisKnowPoints bisKnowPoints) {
        return toAjax(bisKnowPointsService.updateBisKnowPoints(bisKnowPoints));
    }

    /**
     * 删除知识点
     */
    @PreAuthorize("@ss.hasPermi('know:points:remove')")
    @Log(title = "知识点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bisKnowPointsService.deleteBisKnowPointsByIds(ids));
    }
}
